public class Proxy implements Subject{
    private RealSubject realSubject;

    @Override
    public void request() {
        // 在执行前或执行后进行一些额外操作
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        preRequest();
        realSubject.request();
        postRequest();
    }

    private void preRequest() {
        System.out.println("孙悟空查看危险。");
    }

    private void postRequest() {
        System.out.println("孙悟空击败妖怪，确保唐僧安全！");
    }

}
